<?php
/**
 * Created by PhpStorm.
 * User: stupboy
 * Date: 2018/2/4
 * Time: 0:40
 */

namespace app\api\controller\driver;
use app\api\model;
/**
 * @name【推送管理】
 * @baseurl【driver.index】
 */
class Push extends Base
{
    /**
     * @name【绑定推送】
     * @desc【绑定推送】
     * @uri【addBind】
     * @method【post】
     * @param【
     *  dtoken $ string $ abcd $ 校验码 $ 1 #
     * push_user_id $ string $ abcdasdfasdfaf $ 极光用户标识id $ 1 #
     * device_token $ string $ abac $ 设备唯一标识 $ 1#
     * pkg_name $ string $ xdg.1233 $ 包名$ 1#
     * device_brand $ string $ 小米 $ 设备品牌 $ 1#
     * device_model $ string $ 2S $ 设备型号 $ 1#
     * device_version $ string $ 8 $系统版本 $1 #
     * device_type $ int $ 1 $ 设备类型 1安卓 2苹果
     * 】
     * @return【
     * code $ int $ number|1-1 $ 校验码#
     * msg $ string $  $ 错误信息
     * 】
     */
    public function addBind(){
        $this->auth();
        $data['push_user_id']   = input('push_user_id');
        $data['device_token']   = input('device_token');
        $data['device_type']    = input('device_type');
        $data['pkg_name']       = input('pkg_name');
        $data['device_brand']   = input('device_brand');
        $data['device_model']   = input('device_model');
        $data['device_version'] = input('device_version');
        $exist = model\PushBind::get(['user_id'=>$this->driverInfo['user_id']]);
        $pushBind = new model\PushBind();
        if(!empty($exist)){
            $pushBind->save($data,['user_id'=>$this->driverInfo['user_id']]);
            return $this->retSucc();
        }else{
            $data['user_id']        = $this->driverInfo['user_id'];
            if($pushBind->validate(true)->save($data)){
                return $this->retSucc();
            }else{
                return $this->retError($pushBind->getError());
            }
        }
    }

    public function pushUser(){
        $msg  = '{"orderid":"5","from_lon":"112","from_lat":"23","from_addr":"福建省厦门市湖里区万达广场D栋203增加长度增加长度增加长度增加长度增加长度增加长度增加长度","to_lon":"112","to_lat":"28.5555","to_addr":"福建省厦门市湖里区万达广场D栋203增加长度增加长度增加长度增加长度增加长度增加长度增加长度"}';
        (new \app\base\logic\Push())->pushPassenger(['190e35f7e04fdbadc41','1a1018970aac146cb50'],$msg);
        return (new \app\base\logic\Push())->pushDriver(['190e35f7e04fdbadc41','1a1018970aac146cb50'],$msg);
    }
}